
#include <BScript>
#include <BLabel>
#include <BGridLayout>
#include "SourcePanel.h"

SourcePanel::SourcePanel(BWidget* parent) : BGroupBox(parent)
{
	this->setTitle("Source");

	_nameEdit = new BLineEdit();
	_typeEdit = new BLineEdit();
	_pathEdit = new BLineEdit();
	_fileNameEdit = new BLineEdit();

	BGridLayout* gridLayout = new BGridLayout(this);
	gridLayout->addWidget(0, 0, new BLabel("name"));
	gridLayout->addWidget(0, 1, _nameEdit);
	gridLayout->addWidget(1, 0, new BLabel("type"));
	gridLayout->addWidget(1, 1, _typeEdit);
	gridLayout->addWidget(2, 0, new BLabel("path"));
	gridLayout->addWidget(2, 1, _pathEdit);
	gridLayout->addWidget(3, 0, new BLabel("file"));
	gridLayout->addWidget(3, 1, _fileNameEdit);
	gridLayout->setColumnPolicy(0, Policy_Preferred);

	connect(this, Signal_AssetChanged, &SourcePanel::slotAssetChanged);
}
SourcePanel::~SourcePanel()
{

}

void SourcePanel::slotAssetChanged(BObject* object, const BValue& value)
{
	BSource* source = value;
	if (_source != source)
	{
		_source = source;
		if (_source)
		{
			_nameEdit->setText(_source->name());
			_typeEdit->setText(_source->name().ext());
			_pathEdit->setText(_source->fileName());
			BString fileName;
			BScript* script = _source->script();
			fileName << script->path() << '/' << _source->fileName();
			_fileNameEdit->setText(fileName);
		}
	}
}
